using System.Collections.Generic;
using CinemaDirector;
using UnityEngine;

public class LevelUpDisplayControl : MonoBehaviour
{
	public delegate void OnDone();

	public class GameParams
	{
		public string prevLevelName;

		public string newLevelName;

		public float prevLevel;

		public float currentLevel;

		public OnDone onDone;

		public bool isSkillIncrease
		{
			get
			{
				return currentLevel > prevLevel;
			}
		}

		public bool isNextLevelReached
		{
			get
			{
				return Mathf.FloorToInt(currentLevel) > Mathf.FloorToInt(prevLevel);
			}
		}

		public GameParams SetLevelNames(string l1, string l2)
		{
			prevLevelName = l1;
			newLevelName = l2;
			return this;
		}

		public GameParams SetLevels(float prevLevel, float curLevel)
		{
			this.prevLevel = prevLevel;
			currentLevel = curLevel;
			return this;
		}

		public GameParams SetDelegate(OnDone onDone)
		{
			this.onDone = onDone;
			return this;
		}
	}

	public Cutscene addSkill;

	public Cutscene newSkillLevel;

	public Cutscene exitSkillLevel;

	public GGTweenFill tweenFill;

	public GGActionSetTextEvent nextLevelTextTitle;

	public GGActionSetTextEvent nextLevelTextLevel;

	public GGActionSetTextEvent setLevelText;

	public UILabel levelTitle;

	public UILabel levelSubtitle;

	public UISprite levelSlider;

	public GameObject touchToContinue;

	protected GameParams p;

	private List<Cutscene> cutscenes = new List<Cutscene>();

	private List<Cutscene> cutscenesToPlay = new List<Cutscene>();

	private int currentPlayingCutscene;

	protected bool animFinished;

	private void Awake()
	{
		cutscenes.Clear();
		cutscenes.Add(addSkill);
		cutscenes.Add(newSkillLevel);
		cutscenes.Add(exitSkillLevel);
		foreach (Cutscene cutscene in cutscenes)
		{
			cutscene.CutsceneFinished -= CutsceneHandler;
			cutscene.CutsceneFinished += CutsceneHandler;
		}
	}

	private void PlayNextAnim()
	{
		if (currentPlayingCutscene >= cutscenesToPlay.Count)
		{
			animFinished = true;
			touchToContinue.SetActive(true);
		}
		else
		{
			Cutscene cutscene = cutscenesToPlay[currentPlayingCutscene];
			cutscene.Play();
			currentPlayingCutscene++;
		}
	}

	private void CutsceneHandler(object sender, CutsceneEventArgs e)
	{
		PlayNextAnim();
	}

	public void ShowAnim(GameParams p)
	{
		this.p = p;
		if (!p.isSkillIncrease)
		{
			return;
		}
		UITools.ChangeText(levelTitle, p.prevLevelName);
		base.gameObject.SetActive(true);
		animFinished = false;
		touchToContinue.SetActive(false);
		levelSlider.fillAmount = p.prevLevel - Mathf.Floor(p.prevLevel);
		tweenFill.from = levelSlider.fillAmount;
		tweenFill.to = p.currentLevel - Mathf.Floor(p.prevLevel);
		nextLevelTextLevel.text = "Level " + Mathf.FloorToInt(p.currentLevel);
		levelSubtitle.text = "Level " + Mathf.FloorToInt(p.prevLevel);
		cutscenesToPlay.Clear();
		currentPlayingCutscene = 0;
		if (p.isSkillIncrease)
		{
			cutscenesToPlay.Add(addSkill);
			if (p.isNextLevelReached)
			{
				setLevelText.text = p.newLevelName;
				cutscenesToPlay.Add(newSkillLevel);
			}
		}
		PlayNextAnim();
	}

	public void ShowDrawAnim(GameParams p)
	{
		this.p = p;
		UITools.ChangeText(levelTitle, p.prevLevelName);
		base.gameObject.SetActive(true);
		animFinished = false;
		touchToContinue.SetActive(false);
		levelSlider.fillAmount = p.prevLevel - Mathf.Floor(p.prevLevel);
		tweenFill.from = levelSlider.fillAmount;
		tweenFill.to = p.currentLevel - Mathf.Floor(p.prevLevel);
		nextLevelTextLevel.text = "Level " + Mathf.FloorToInt(p.currentLevel);
		levelSubtitle.text = "Level " + Mathf.FloorToInt(p.prevLevel);
		cutscenesToPlay.Clear();
		currentPlayingCutscene = 0;
		PlayNextAnim();
	}

	public void OnContinue()
	{
		if (animFinished)
		{
			base.gameObject.SetActive(false);
			if (p.onDone != null)
			{
				p.onDone();
			}
		}
	}
}
